import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code3 {
    public static int M = 110;
    public static int n,m;
    public static int[][] arr = new int[M][M];
    public static int[][] dp = new int[M][M];//记忆化搜索
    public static int[] dx = {1,-1,0,0};
    public static int[] dy = {0,0,1,-1};

    public static int dfs(int i,int j) {
        int len = 1;
        if(dp[i][j]!=0) return dp[i][j];

        for(int k=0;k<4;k++) {
            int x = i+dx[k];int y = j+dy[k];
            if(x>=0 && x<n && y>=0 && y<m && arr[x][y]<arr[i][j]) {
                len = Math.max(len,dfs(x,y)+1);
            }
        }
        dp[i][j] = len;
        return len;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();m = in.nextInt();
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                arr[i][j] = in.nextInt();
            }
        }
        int ret = 0;
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                ret = Math.max(ret,dfs(i,j));
            }
        }
        System.out.print(ret);
    }
}